<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增工程项目')" />
	<th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-hadoopProject-add">
			<div class="form-group">
				<label class="col-sm-3 control-label"><span style="color: red; ">*</span>项目名称(中文)：</label>
				<div class="col-sm-8">
					<input id="nameCn" name="nameCn" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label"><span style="color: red; ">*</span>项目名称(英文)：</label>
				<div class="col-sm-8">
					<input id="nameEn" name="nameEn" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label"><span style="color: red; ">*</span>项目版本：</label>
				<div class="col-sm-8">
					<input id="projectVersion" name="projectVersion" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">项目描述：</label>
				<div class="col-sm-8">
					<input id="description" name="description" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label"><span style="color: red; ">*</span>需求方：</label>
				<div class="col-sm-8">
					<div class="input-group">
						<input name="demanderDeptId" id="demanderDeptId" type="hidden"/>
						<input name="demanderDeptName" onclick="selectDeptTree()" id="demanderDeptName" type="text" placeholder="请选择归属组织" class="form-control" required>
						<span class="input-group-addon"><i class="fa fa-search"></i></span>
					</div>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label"><span style="color: red; ">*</span>需求人：</label>
				<div class="col-sm-8">
					<select id="demanderUserId" name="demanderUserId" class="form-control select2-hidden-accessible" disabled>
					</select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">项目规模：</label>
				<div class="col-sm-8">
					<input id="projectSize" name="projectSize" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">工作量：</label>
				<div class="col-sm-8">
					<input id="projectEffort" name="projectEffort" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label"><span style="color: red; ">*</span>大数据平台：</label>
				<div class="col-sm-8">
					<div class="input-group">
						<input name="platformId" id="platformId" type="hidden"/>
						<input name="platformName" onclick="selectHadoopPlatformTree()" id="platformName" type="text" placeholder="请选择Hadoop集群" class="form-control" required>
						<span class="input-group-addon"><i class="fa fa-search"></i></span>
					</div>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label"><span style="color: red; ">*</span>租户：</label>
				<div class="col-sm-8">
					<select id="tenantId" name="tenantId" class="form-control select2-hidden-accessible" disabled>
					</select>
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
	<th:block th:include="include :: select2-js" />
    <script type="text/javascript">
		var prefix = ctx + "hadoop/hadoopProject"
		$("#form-hadoopProject-add").validate({
			rules:{
                name:{
					required:true,
                    minlength: 2,
                    maxlength: 20,
                    remote: {
                        url: prefix + "/checkProjectNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            nameCn : function() {
                                return $.common.trim($("#nameCn").val());
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
				},
                projectVersion:{
                    required:true,
                    minlength: 2,
                    maxlength: 20,
				},
                demanderDeptName:{
                    required:true
				},
                demanderUserId:{
                    required:true
				}

			},
			focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/add", $('#form-hadoopProject-add').serialize());
	        }
	    }

        /*项目管理-新增-选择组织树*/
        function selectDeptTree() {
            var treeId = $("#demanderDeptId").val();
            var deptId = $.common.isEmpty(treeId) ? "100" : $("#demanderDeptId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
            var options = {
                title: '选择组织',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowParents(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#demanderDeptId").val(body.find('#treeId').val());
                $("#demanderDeptName").val(body.find('#treeName').val());
                layer.close(index);

                //项目经理下拉框
                $("#demanderUserId").removeAttr("disabled");
                getProjectManager();
            }
        }

        function doSubmitPlatform(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowParents(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#platformId").val(body.find('#treeId').val());
                $("#platformName").val(body.find('#treeName').val());
                layer.close(index);

                $("#tenantId").removeAttr("disabled");
                getTenant();
            }
		}

		function getTenant(){
            var platformId=$("#platformId").val();
            $.ajax({
                async : false,
                type : "GET",
                url : prefix + '/getTenant/'+platformId,
                dataType : "json",
                success : function(R) {
                    $("#tenantId").empty();
                    $.each(R.data, function(i, item) {
                        $("#tenantId").append("<option value='"+item.id+"'>"+item.tenant+"</option>");
                    });
                },
                error : function(request, status, error) {
                }
            });
		}

        // 选择hadoop平台树
        function selectHadoopPlatformTree(){
            var url = ctx + "hadoop/hadoopProject/selectPlatformTree";
            var options = {
                title: '选择大数据平台',
                width: "380",
                url: url,
                callBack: doSubmitPlatform
            };
            $.modal.openOptions(options);
		}

        function getProjectManager(){
            var demanderDeptId=$("#demanderDeptId").val();
            $.ajax({
                async : false,
                type : "GET",
                url : prefix + '/getManagerRoleUserByDeptId/'+demanderDeptId,
                dataType : "json",
                success : function(R) {
                    $("#demanderUserId").empty();
                    $.each(R.data, function(i, item) {
                        $("#demanderUserId").append("<option value='"+item.userId+"'>"+item.userName+"</option>");
                    });
                },
                error : function(request, status, error) {
                }
            });

		}
	</script>
</body>
</html>
